package cn.yx.common.core.pojo.singletable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * <p>分页查询条件对象</p>
 *
 * @author Wgssmart
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "PageCond", description = "单表分页查询对象")
public class PageCond extends SingleCond {

    private static final int DEFAULT_PAGE_SIZE = 20;

    /**
     * 第几页
     */
    @ApiModelProperty(value = "第几页（默认为1）", example = "1")
    private Integer pageNum = 1;
    /**
     * 每页多少项
     */
    @ApiModelProperty(value = "每页多少项（默认为20）", example = "1")
    private Integer pageSize = DEFAULT_PAGE_SIZE;

    public Integer getPageNum() {
        return pageNum > 0 ? pageNum : 1;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum > 0 ? pageNum : 1;
    }

    public Integer getPageSize() {
        return pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
    }

    public int getBeginIndex() {
        return ((pageNum > 0 ? pageNum : 1) - 1) * (pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE);
    }

}
